/*
 *说明：用户与用户组关系表 未选用户列表脚本
 *
 *@author liuxun 2012-03-06
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            //{title:'用户组名称',field:'usr_grp_name',align:'center',width:80},

            {title:'统一登录名',field:'login_name',align:'center',width:60},
            
            {title:'用户姓名',field:'usr_name',align:'center',width:80},
            
            {title:'用户类型',field:'usr_type_decode',align:'center',width:60},
            
            {title:'机构名称',field:'org_name',align:'center',width:150},
            
            {title:'负责人',field:'is_leader',align:'center',width:40,
            	formatter:function(value, rec){
            		 return value == '1' ? "<font color='green'>√</font>" : '';
            	}
            },
            
            {title:'操作员',field:'is_operator',align:'center',width:40,
            	formatter:function(value, rec){
            		 return value == '1' ? "<font color='green'>√</font>" : '';
            	}
            },
            
            {title:'用户状态',field:'usr_status_decode',align:'center',width:40}
            
        ]],
		pagination:true,
		singleSelect: false
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#okBtn').click(doOk);
	$('#cancelBtn').click(closeWin);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'A_USR_USRGRP!queryNotselectedUsrList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//查看明细
function showInfo(key) {
	var url = 'A_USR_USRGRP!showInfo.do?model.key=' + key;
	openWin(url,'pop'); 
}

//保存按钮操作
function doOk() {

	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  
	
	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}
	var params = $ .param({'id' : ids}, true);

	showSystemProccessing();
	var options = { 
			url: 'A_USR_USRGRP!doInsert.do?' + params,
			type: 'post',
			success: function(data){
			removeSystemProccessing();
			getOpenerWin().afterOK();
			showInfoWin('操作成功!', refreshWin);
		}
	};

	opeForm.ajaxSubmit(options);
}

//选择机构
function select_a_org() {
	var action = "A_ORG!showTree.do";
	var row = showModalWin(action);
	
	if (row) {
		$('#org_id').val(row.attributes.org_id);
		$('#org_name').val(row.attributes.org_name);
	}
	
}
